<?php
    $url = new Url(); 
    $forder_upload = "ringBack"; 
    $arr_status = LoadConfig::$status;    
    $link_url = Yii::app()->params["urlImages"]."upload_base.php?forder_upload=".$forder_upload;   
    $link_avatar = Yii::app()->params["urlImages"]."upload_avatar.php?forder_upload=".$forder_upload; 
?>
<link rel="stylesheet" href="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/css/swfupload.css" type="text/css" />
<link rel="stylesheet" href="<?php echo Yii::app()->params['static_url_cp']; ?>css/jquery.autocomplete.css" type="text/css" />
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/swfupload.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/swfupload.queue.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/fileprogress.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/handlers.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['tiny_url_cp'];?>js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['static_url_cp'];?>js/tinymce_submit.js"></script>   
<script type="text/javascript" src="<?php echo Yii::app()->params['static_url_cp'];?>js/jquery-ui.min.js"></script>   
<script type="text/javascript" src="<?php echo Yii::app()->params['static_url_cp'];?>js/jquery.autocomplete.js"></script>   

<script type="text/javascript">
    window.onload = function() {
        
        var configUploadDataOther = {
            flash_url:"<?php echo Yii::app()->params["urlImages"];?>lib_upload/js/swfupload.swf",
            create_date:'<?php echo $data["create_date"];?>',
            button_image_url:"<?php echo Yii::app()->params["urlImages"];?>lib_upload/images/buttonUpload.png",
            upload_url: "<?php echo $link_url;?>", 
            file_types: "*.mp3;*.wav;", 
            file_upload_limit : 20, 
            file_queue_limit : 1, 
            debug : false
        }
        
        configUploadOther(configUploadDataOther);   
    };
     
    function uploadResponseOther(serverData){  
        try {
            $("#txtFileName_other").val(""); 

            var response = $.parseJSON(serverData);      
            if(response.code==404){
                alert(response.message);return false;
            }  
            var filename = response.filename;    
            var path = response.path;
            var message = response.message;
            var code = response.code;
            var extension = response.extension;
            var filesize = response.filesize;  
            $("#file").val(filename);
            var link_file = '<?php echo Yii::app()->params["urlImages"].$forder_upload.'/';?>'+path +'/'+ filename +'';
            $("#show_file").html('Tên file: <strong>' + link_file + '</strong>&gt;&gt;<a target="_blank" href="<?php echo $url->createUrl("ringBack/index")?>?link='+link_file+'">Xem thử</a>');              
        } catch (e) {

        };
    }
    function ajaxUpdateRing(){
        tinyMCE.triggerSave();
        var id = '<?php echo $data["id"]?>';
        var title_ring = $("#title_ring").val();        
        var singerId = $("#singerId").val(); 
        var singer_name = $("#singers_search").val(); 
        var categoryId = $("#categoryId").val();
        var file_music = $("#file_music").val();  
        var position = $("#position").val();
        var lyrics = $("#lyrics").val();
        var file = $("#file").val();
        var status = $("#status").val();   
        var telco1 = $("#telco1").val();   
        var telco2 = $("#telco2").val();   
        var telco3 = $("#telco3").val();   
        var telco4 = $("#telco4").val();   
        var telco5 = $("#telco5").val();   
        var strUrl = "<?=$url->createUrl("ringBack/ajaxUpdateRing") ?>";  
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                id:id, 
                title_ring:title_ring,                
                singerId:singerId,
                singer_name:singer_name, 
                categoryId:categoryId,
                lyrics:lyrics,    
                status:status,
                file:file, 
                id:id,
                telco1:telco1,
                telco2:telco2,
                telco3:telco3,
                telco4:telco4,
                telco5:telco5,                
            },
            success: function(msg){
                if(msg == 1){
                    alert('Sửa thành công');
                    history.go(-1);
                }else{
                    $("#show_error").html(msg);
                }
            },
            beforeSend:function(){
                $("#button_save").attr("disabled","disabled");
            },
            complete:function(){
                $("#button_save").removeAttr("disabled"); 
            }          
        });
    }
    
    function getSinger(name,singerId){
        $("#singer_search").val(name);
        $("#singerId").val(singerId);
    } 
    function clickOne(singers_search){
        if(singers_search == "Tìm kiếm nhanh"){
            singers_search = "";
        }
        $('#singers_search').val(singers_search);
    }
    
    $(document).ready(function() {
        var dataTotal = [<?php echo $str;?>];
        $("#singers_search").autocomplete({        
            minChars: 0,        
            sortFunction: function(a, b, filter) {
                var f = filter.toLowerCase();
                var fl = f.length;
                var a1 = a.value.toLowerCase().substring(0, fl) == f ? '0' : '1';
                var b1 = b.value.toLowerCase().substring(0, fl) == f ? '0' : '1';
                if (a1 > b1) {
                    return 1;
                }
                if (a1 < b1) {
                    return -1;
                }
                return 0;
            },
            showResult: function(value, data) {                        
                return value;
            },
            onItemSelect: function(item) {            
                var singerId = item.data[0];                
                $("#singerId").val(singerId);
            },
            onNoMatch: function() {            
                $("#singers_search").val("");
                $("#singerId").val("");

            },
            data:dataTotal
        });
    });
</script>
<div id="container">
    <div class="main clearfix">
        <div class="Tabs clearfix">
            <ul class="clearfix">
                <li><a class="active" href="<?php echo Url::createUrl('ringBack/index');?>"><span>Quản trị nhạc chờ</span></a></li>
                <li><a href="<?php echo Url::createUrl('ringBack/singer');?>"><span>Quản trị ca si/nhóm nhạc</span></a></li>
                <li><a href="<?php echo Url::createUrl('ringBack/category');?>"><span>Quản trị thể loại nhạc</span></a></li>
            </ul>                
        </div>
        <div class="box clearfix bottom30">
            <ul class="form1 fl add-lys" style="width:500px">
                <li class="clearfix"><label><strong>Tên bài hát </strong>:</label>
                    <div class="filltext">
                        <input type="text" style="width:331px;margin-right:10px" value="<?php echo $data["title"]?>" id="title_ring"> 
                    </div>
                </li>
                <li class="clearfix"><label><strong>Tên ca sỹ </strong>:</label>
                    <div class="filltext"> 
                        <span class="quick-seah">
                            <input type="text" name="singers_search" id="singers_search" autocomplete="off" onClick="clickOne(this.value);" value="<?php echo $data["singer_name"]?>" style="width:250px;margin-right:10px">
                            <input type="hidden" name="singerId" id="singerId" value="<?php echo $data["singerId"]?>">
                            <ul class="menu-sub"></ul>
                        </span> 
                    </div>
                </li>
                <li class="clearfix"><label><strong>Upload file nhạc </strong>:</label>
                    <div class="filltext">
                        <input type="hidden" id="txtFileName_other" readonly="readonly"/>
                        <input type="text" style="width:196px" value=""> &nbsp; 
                        <span id="spanButtonPlaceHolder_other"></span>
                    </div>
                </li>
                <li class="clearfix"><label>&nbsp;</label> 
                    <div class="fieldset flash" id="fsUploadProgress_other">
                        <span class="legend">File upload</span>
                    </div>
                    <input type="hidden" id="file" value="<?php echo $data["file"];?>"/> 
                </li>
                <li class="clearfix"><label><strong>Thể loại </strong>:</label>
                    <div class="filltext">
                        <select style="width:150px;margin-right:10px" id="categoryId">
                            <?php foreach($data_category as $category){?>
                            <option onclick="$('#title').val('<?php echo $category['title'];?>')" value="<?php echo $category['id'];?>" <?php echo $data['categoryId']==$category['id']? 'selected="selected"':"";?>><?php echo $category['title'];?></option>
                            <?php }?>                          
                        </select>  
                    </div>
                </li>
                <li class="clearfix"><label><strong>Lời bài hát </strong>:</label>
                    <div class="filltext"> 
                        <textarea id="lyrics" name="lyrics"><?php echo $data["lyrics"];?></textarea> 
                    </div>
                </li>
                <li class="clearfix"><label><strong>Trạng thái</strong>:</label>
                    <div class="filltext">
                        <select style="width:203px;" id="status">
                            <?php foreach($arr_status as $key=>$value){?>
                                <option value="<?php echo $key;?>" <?php echo $key == $data["status"] ? 'selected="selected"':''?>><?php echo $value?></option>
                                <?php }?>
                        </select>
                    </div>
                </li>
                <li class="clearfix">
                    <label>Mã Viettel:</label> 
                    <div class="filltext">
                        <input type="text" value="<?php echo $viettel;?>" style="width:220px" id="telco1">
                    </div>
                </li>
                <li class="clearfix">
                    <label>Mã Mobifone:</label> 
                    <div class="filltext">
                        <input type="text" value="<?php echo $mobifone;?>" style="width:220px" id="telco2">
                    </div>
                </li>
                <li class="clearfix">
                    <label>Mã Vinaphone:</label> 
                    <div class="filltext">
                        <input type="text" value="<?php echo $vinaphone;?>" style="width:220px" id="telco3">
                    </div>
                </li>
                <li class="clearfix">
                    <label>Mã Vietnammobile:</label> 
                    <div class="filltext">
                        <input type="text" value="<?php echo $vietnammobile;?>" style="width:220px" id="telco4">
                    </div>
                </li>
                <li class="clearfix">
                    <label>Mã Beeline:</label> 
                    <div class="filltext">
                        <input type="text" value="<?php echo $beeline;?>" style="width:220px" id="telco5">
                    </div>
                </li>
                <li class="clearfix"><label>&nbsp;</label>
                    <div class="filltext">
                        <input type="button" id="button_save" value=" Sửa " class="btn-bigblue" onclick="ajaxUpdateRing();"> 
                        &nbsp;
                        <input onclick="history.go(-1)" type="button" value=" Quay lại " class="btn-bigblue">
                    </div>
                </li>
                <li class="clearfix"><label>&nbsp;</label>
                    <div class="filltext" style="color: red;" id="show_error"></div>
                </li>
            </ul>
    </div>
</div>